import React from 'react'
import {Form, Radio, Input, Button, message, Col} from 'antd'
import {fetchPost} from '../../../../../utils/request'

const FormItem = Form.Item
const {TextArea} = Input

const formItemLayout = {
  labelCol: {
    xs: {span: 10},
    sm: {span: 10}
  },
  wrapperCol: {
    xs: {span: 14},
    sm: {span: 14}
  }
}

class Transfer extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      info: props.info
    }
  }

  componentWillReceiveProps(nextProps, nextContext) {
    if (nextProps.info !== this.state.info) {
      this.setState({
        info: nextProps.info
      })
    }
  }

  handleSubmit = e => {
    e.preventDefault()
    this.props.form.validateFields((err, values) => {
      if (!err) {
        if (!values.language1) {
          message.error('Please select a language')
          return
        }
        // 去除空值
        for (var key in values) {
          if (!values[key]) {
            delete values[key]
          }
        }
        let params = {
          collectionNo: this.state.info.collectionNo,
          userLanguage: values.language1
        }
        fetchPost('/collection/v2/order/transfer', params).then(json => {
          if (json.code === 0) {
            message.info('Success')
            this.props.form.resetFields()
            this.props.onOk()
          } else {
            message.error(json.msg)
          }
        })
      }
    })
  }

  render() {
    const {getFieldDecorator} = this.props.form
    return (
      <div>
        <Form horizontal onSubmit={this.handleSubmit}>
          <FormItem label="Choose user-Speaking Language:">
            {getFieldDecorator('language1')(
              <Radio.Group>
                {/*<Radio.Button value="English">English</Radio.Button>*/}
                <Radio.Button value="Hindi">Hindi</Radio.Button>
                <Radio.Button value="Telugu">Telugu</Radio.Button>
                <Radio.Button value="Kannada">Kannada</Radio.Button>
                <Radio.Button value="Tamil">Tamil</Radio.Button>
                <Radio.Button value="Malayalam">Malayalam</Radio.Button>
              </Radio.Group>
            )}
          </FormItem>
          {/*<FormItem label="No options,Please enter the Language below">*/}
          {/*  {getFieldDecorator('language2')(*/}
          {/*    <Input style={{width: 200}} placeholder='User language'/>*/}
          {/*  )}*/}
          {/*</FormItem>*/}
          <FormItem {...formItemLayout}>
            <Button type="primary" htmlType="submit" style={{float: 'right'}}>
              Submit
            </Button>
          </FormItem>
        </Form>
      </div>
    )
  }
}

Transfer = Form.create()(Transfer)
export default Transfer
